$(function () {
    load();
})

function load() {
    // 头像 账户名
    $.post("Account.do/LoadAccount", function (sdata) {
        console.log(sdata)
        localStorage.setItem("user",JSON.stringify(sdata));
        if (sdata != null) {
            if (sdata.image != null) {
                $("#accimg").prop("src", "image/" + sdata.image)
            }
            $("#accname").text(sdata.account);
        } else {
            location.href = "login.html";
        }
    })

    // 菜单栏
    $.post("AccountRoleMenu.do/QueryIndex", function (sdata) {
        console.log(sdata)
        $("#caidan").empty();
        let str = "";
        for (let i = 0; i < sdata.length; i++) {
            str += "<li class=\"nav-item\">\n" +
                "    <a href=\"#\" class=\"nav-link\">\n" +
                "         <i class=\"far fa-circle nav-icon\"></i>\n" +
                "        <p> "+sdata[i].menuname+"\n" +
                "            <i class=\"right fas fa-angle-left\"></i>\n" +
                "        </p>\n" +
                "    </a>\n" +
                "    <ul class=\"nav nav-treeview\">";
            $.each(sdata[i].armlist, function (index, item) {
                str += "   <li class=\"nav-item\">\n" +
                    "          <a style='font-weight: 500;font-size: 15px;' href=\""+item.menuurl+"\" class=\"nav-link\">\n" +
                    "             <i style='margin-left: 15px;color: darkgrey'>@</i>\n" +
                    "             <p>"+item.menuname+"</p>\n" +
                    "          </a>\n" +
                    "      </li>";
            })
            str += "            </ul>\n" +
                "                    </li>";
        }
        $("#caidan").append(str);
    })
}

function tuichu() {
    $.post("/TuiChu.do", function (sdata) {
         location.href = "login.html";
    })
}